package one.stand.controller;

import com.jmp.autocofiguration.web.interceptor.SecurityAuthCheck;
import com.jmp.feign.WechatAdminFegin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import one.stand.model.ResultModel;
import one.stand.request.CompanyAccountRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: QIK
 * @CreateDate: 2019/5/13 16:15
 */
@RestController
@RequestMapping("crmPc/component")
@Api(description = "小程序管理")
public class ComponentController extends BaseController {
    @Autowired
    protected WechatAdminFegin wechatAdminFegin;

    @ApiOperation(value = "小程序授权")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "需要授权的appid", required = true, paramType = "String"),
            @ApiImplicitParam(name = "accountType", value = "需要授权的appid", required = true, paramType = "String"),
    })
    @PostMapping("componentloginpage")
    @SecurityAuthCheck(isBoss = true)
    public ResultModel<String> componentloginpage(@RequestAttribute CompanyAccountRequest request) {
        return wechatAdminFegin.componentloginpage(request);
    }

    @ApiOperation(value = "授权成功回调")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "authCode", value = "authCode", required = true, paramType = "String"),
    })
    @PostMapping("componentCallBack")
    public ResultModel componentCallBack(@RequestAttribute CompanyAccountRequest request) {
        return wechatAdminFegin.componentCallBack(request);
    }

    @ApiOperation(value = "获取账号信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "appId", value = "appId", required = true, paramType = "String"),
    })
    @PostMapping("getAuthorizerInfo")
    @SecurityAuthCheck(isBoss = true)
    public ResultModel getAuthorizerInfo(@RequestAttribute CompanyAccountRequest request) {
        return wechatAdminFegin.getAuthorizerInfo(request);
    }
}
